** generating MONTHLY avg 9am, noon, 5pm, 7pm prices


use "$P_Data/Price/price_at_9_12_17_19.dta", clear

fsort StID Time
by StID Time: keep if _n==1

gen hour = hh(Time)
gener date = dofc(Time)

gener month = month(date)
gener year = year(date)

gener year_month= ym(year,month)

gcollapse e5, by(StID year_month hour)
rename e5 mean_month_hour_e5_price 

replace mean_month_hour_e5_price = mean_month_hour_e5_price/1000

sort StID year_month hour 
by StID year_month: gener mean_price_9 = mean_month_hour_e5_price[1]
by StID year_month: gener mean_price_12 = mean_month_hour_e5_price[2]
by StID year_month: gener mean_price_17 = mean_month_hour_e5_price[3]
by StID year_month: gener mean_price_19 = mean_month_hour_e5_price[4]

by StID year_month: keep if _n==1
keep StID year_month mean_price_9 mean_price_12 mean_price_17 mean_price_19 

save "$P_Data_Processed/mean_hourly_prices.dta", replace
